<?php
use Inationsoft\NS\Core\Model;

class BlockModel extends Model {
	function __construct() {
		parent::__construct('koma_blocks', 'block_id');
	}

	function get($path) {
		if($this->find(null, array('application_path' => $path))) {
			return $this->toArray(1);
		}

		return false;
	}

	function getAll($columns = null, $condition = null, $order = null, $offset = null, $limit = null) {
		$this->findAll($columns, $condition, $order, $offset, $limit);

		return $this->toArray();
	}

	function saveData($data, $is_edit = false) {
		if($is_edit && isset($data[$this->PrimaryKey])) {
			if(!$this->find(null, array($this->PrimaryKey => $data[$this->PrimaryKey]))) return false;
		}

		$this->populate($data, false);

		if(($id = $this->save()) === true) {
			$id = $this->{$this->PrimaryKey};
		}

		return $id;
	}

	function deleteSelected($ids) {
		if(empty($ids)) return false;
    
		$criteria = $this->createFilterCriteria();
		$criteria->in($this->PrimaryKey, $ids);

		return $this->deleteAll($criteria);
	}
}
?>